package com.app.testDemo.service.impl;


import org.apache.commons.collections.map.HashedMap;
import com.app.testDemo.mapper.DemoMapper;
import com.app.testDemo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by zhangzhiling on 2017/7/28.
 */
@Service("demoService")
public class DemoServiceImpl implements DemoService {

    @Autowired
    private DemoMapper demoMapper;

    @Override
    public List<Map<String,Object>> list(){
        return demoMapper.list();
    }

    @Override
    public List<Map<String,Object>> saleType(){

        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        String[] str={"限制","多买优惠","会员特价","加价购","京豆优惠购","跨店铺满减",
                "满减","满赠","限购","优惠券","赠京豆","赠品",};

        for(int i=0; i<str.length;i++){
            Map<String,Object> map = new HashedMap();
            String keyword = str[i];
            map.put("key",keyword);
            map.put("count",demoMapper.saleType(keyword));
            list.add(map);
        }
        Map<String,Object> ma = new HashedMap();
        ma.put("key","无活动");
        ma.put("count",demoMapper.saleType1());
        return list;
    }

    @Override
    public List<Map<String,Object>> getPriceCount(){
        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();

        String[] str={"0-100","101-300","301-500","501-700","701-"};

        for(int i=0; i<str.length;i++){
            Map<String,Object> map = new HashedMap();
            String keyword = str[i];
            map.put("key",keyword);
            if(keyword.equals("0-100")){
                map.put("count",demoMapper.getPriceCount(null,100));
            }
            if(keyword.equals("101-300")){
                map.put("count",demoMapper.getPriceCount(100,300));
            }
            if(keyword.equals("301-500")){
                map.put("count",demoMapper.getPriceCount(300,500));
            }
            if(keyword.equals("501-700")){
                map.put("count",demoMapper.getPriceCount(500,700));
            }
            if(keyword.equals("701-")){
                map.put("count",demoMapper.getPriceCount(700,null));
            }

            list.add(map);
        }

        return list;

    }

    @Override
    public List<Map<String,Object>> getEvaluate(){
        return demoMapper.getEvaluate();
    }
}
